<?php
/*
* File：管理卡密
* Author：易如意
* QQ：51154393
* Url：www.eruyi.cn
*/

require_once 'globals.php';
include_once 'header.php';

 $sql="select * from eruyi_kami where 1";
 $queryc=$db->query($sql);
 $nums=$db->num_rows($queryc);
 $enums=30;  //每页显示的条目数 
 $page=isset($_GET['page']) ? intval($_GET['page']) : 1;
 $url="adm_kami.php?page=";
 $bnums=($page-1)*$enums;
 
 $id = isset($_POST['id']) ? $_POST['id'] : '';
 if($id){
	$ids = '';
	foreach ($id as $value) {
		$ids .= $value.",";
	}
	$ids = rtrim($ids, ",");
	$sql="DELETE FROM `eruyi_kami` WHERE `id` in ($ids)";
	$query=$db->query($sql);
	if($query){
		echo "<script>alert('删除成功');</script>";
	}
 }
 
 $KMtype = array(
	'TK'=>"天卡",
	'ZK'=>"周卡",
	'YK'=>"月卡",
	'BNK'=>"半年卡",
	'NK'=>"年卡",
	'YJK'=>"永久卡",
 );
?>
<form action="adm_kami.php" method="post" name="skami" id="skami">
<label for="user" />查找卡密</label>
<input type="text" name="kami" /><input type="submit" value="查找" />
</form>
<form action="" method="post" name="form_log" id="form_log">
  <table width="100%" id="adm_log_list" class="item_list">
  <thead>
      <tr>
		<th><input type="checkbox" onclick="checkAll();" class="ids" id="all"/></th>
        <th><b>ID</b></th>
		<th><b>卡密</b></th>
		<th><b>类型</b></th>
		<th><b>状态</b></th>
		<th><b>使用者</b></th>
		<th><b>使用时间</b></th>
      </tr>
	</thead>
 	<tbody>
<?php
 $kami = isset($_POST['kami']) ? addslashes(trim($_POST['kami'])) : '';
 if($kami != ''){
 $sql="select * from eruyi_kami where kami='$kami' order by id desc limit $bnums,$enums";
 }else{
 $sql="select * from eruyi_kami where 1 order by id desc limit $bnums,$enums";
 }
 $query=$db->query($sql);
 while($rows=$db->fetch_array($query)){
?>
      <tr>
      <td><input type="checkbox" name="id[]" value="<?php echo $rows['id']; ?>" class="ids" /></td>
	  <td><?php echo $rows['id']; ?></td>
      <td><?php echo $rows['kami']; ?></td>
      <td><?php echo $KMtype[$rows['type']]; ?></td>
	  <td><?php if($rows['new']=='n'):?><font color=red>已用<?php else: ?><font color=green>可用<?php endif; ?></font></td>
	  <td><?php if($rows['new']=='n'): echo $rows['user']; endif; ?></td>
	  <td><?php if($rows['new']=='n'): echo gmdate("Y-m-d H:i:s",$rows['date']+8*3600); endif; ?></td>
      </tr>
<?php
 }
?>
	</tbody>
	</table>
	<div class="list_footer">
	选中项：<a href="javascript:void(0);" onclick="delsubmit()" class="care">删除</a>
	</div>
</form>
<?php if($kami == ''): ?>
<div class="page" style="text-align:center;"><?php echo pagination($nums,$enums,$page,$url); ?></div>
<?php endif; ?>
<div style="height:60px;"></div>
<script>
function checkAll() {
    var code_Values = document.getElementsByTagName("input");
	var all = document.getElementById("all");
    if (code_Values.length) {
        for (i = 0; i < code_Values.length; i++) {
            if (code_Values[i].type == "checkbox") {
                code_Values[i].checked = all.checked;
            }
        }
    } else {
        if (code_Values.type == "checkbox") {
            code_Values.checked = all.checked;
        }
    }
}
function delsubmit(){
	var delform = document.getElementById("form_log");
	delform.submit();
}
var div = document.getElementById('adm_kami'); 
div.setAttribute("class", "show"); 
</script>
<?php 
include_once 'footer.php';
?>